package com.zx.shop.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.*;
//import javax.swing.JFrame;
//import javax.swing.JLabel;
//import javax.swing.JMenuItem;
//import javax.swing.JPanel;
//import javax.swing.JTextField;

import com.zx.shop.bean.Category;
import com.zx.shop.dao.ICategoryDao;
import com.zx.shop.dao.impl.CategoryDaoImpl;

public class AddCategoryFrame extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public AddCategoryFrame() 
	{
		this.setTitle("添加分类");
		this.setBounds(120, 120, 300, 200);
		
		JPanel p1 = new JPanel();
		JLabel l1 = new JLabel("分类名:");
		JTextField tf = new JTextField(20);
		JButton btn1 = new JButton("添加");
		
		p1.add(l1);
		p1.add(tf);
		p1.add(btn1);
		
		this.add(p1);
		
		
		btn1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				String cname = tf.getText();
				ICategoryDao dao = new CategoryDaoImpl();
				try {
					
					dao.insert(new Category(0,cname));
					JOptionPane.showMessageDialog(null,"添加成功");
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			}
		});
	}

}
